function fetchNewBids(bids){
	var even = true;
	for(var i = bids.length - 1;i > -1; i--){
		var tableRow = document.createElement('tr');
		if(even)
			tableRow.setAttribute('class', 'alt');
		even = !even;
		tableRow.innerHTML += getTableRowText(bids[i]);
		var container = getBidsTableBody();
		container.insertBefore(tableRow, container.firstChild);
	}
	showTable();
}

var showTable = function(){
	if(getBidsTable() != null && getBidsTable().rows != null && getBidsTable().rows.length > 0){
		document.getElementById("bids").style.visibility = "visible";
		//showTable = function() {};
	}
};

function getTableRowText(bid){
	var ifOver = (bid.ifOver) ? ((bid.ifWon) ? "won": "lost") : "still";
	return bid.itemName + "&nbsp;&nbsp;" + bid.money + "$" +
	"&nbsp;&nbsp;" + ifOver;
}

function updateBidsTable(){
	var bidsTable = document.getElementById('bidstsablebody');
	for(var i = 0; i < newBidsArr.length ; i++){
		if(newBidsArr[i].ifOver){
			bidsTable.rows[i].innerHTML = getTableRowText(newBidsArr[i]); 	
		}
}
}

function refetchNewBidsFromCache(){
	fetchNewBids(newBidsArr);
}

//placing a new bid

function placeBid(){
	var params = new Object();
	var innerdocument = getNestedPage().contentDocument;
	params.money = innerdocument.getElementById("money").value;
	params.itemID = innerdocument.getElementById("itemid").value;
	if(params.money < 0 )
		showError('invalid params');
	else
	newBid(params);
}

function showPlaceBidform(){
	var innerdocument = getNestedPage().contentDocument;
	innerdocument.getElementById('bid').style.visibility = "visible"; 
}

function hidePlaceBidform(){
	if(isViewItemPage()){
	var innerdocument = getNestedPage().contentDocument;
	innerdocument.getElementById('bid').style.visibility = "hidden"; 
	}
}

function getBidsTable(){
	return document.getElementById('bidstsablebody');
}

function hideBidsTable(){
	 document.getElementById('bids').style.visibility = "hidden"; 
}

setTimeout(function(){showTable();}, 50);

